Formal Logic

Formal Logic

Formal Logic: The study of reasoning, specifically whether something is true or false.

Statement

Statement / Proposition: A sentence that is either true or false.

Examples of Valid Statements (crossed-out aren’t valid):

Logic

Logical methods are used to prove that programs do what they are designed to do.

Example of a Logically-Sound Proof/Derivation:

  1. All mathematicians wear sandals
  2. Anyone wears sandals is an algebraist
  3. Therefore, all mathematicians are algebraists

Binary Connectives

Example of Logical Connective and Disjunction:

ABA \land BA \lor B
TTTT
TFFT
FTFT
FFFF

Example of Logical Implication and Equivalence Connective:

ABA \rightarrow BB \rightarrow A(A \rightarrow B) \land (B \rightarrow A)
TTTTT
TFFTF
FTTFF
FFTTT

Truth Table

Truth Table: Table that displays the truth values of a statement which correspond to the different combinations of truth values for the variables.

General Structure of a Truth Table:

How-To Make a Truth Table:

  1. Create columns:
    1. Start with statement variables (A, B, etc.)
    2. Intermediate values (parts of the well-formed formula)
      • Use personal taste for how much you want to split up the problem
    3. End with the target well-formed formula.
  2. List all truth value combinations for statement variables
  3. Solve for each row.

Note: Truth tables get graded in the test/homework by whether the target truth values are correct

Tautological Equivalence between \rightarrow and \lor

A \rightarrow B and A` \lor B are tautologically equivalent

Proof: Truth table for A \rightarrow B \equiv A` \lor B

ABA \to B\lnot A \lor B
TTTT
TFFF
FTTT
FFTT

Example: These two statements are equivalent

  1. “If you do your homework, then you will fail”
  1. “Either you do your homework or you will fail”

Well-Formed Formula (WFF)

Well-Formed Formula: A combination of letters, connectives, and parenthesis in a meaningful expression.

Priority of Connectives

  1. Innermost Parenthesis (progress outwards)
  2. Negation (\lnot)
  3. Conjunction (\land)
  4. Disjunction (\lor)
  5. Implication (\rightarrow)
  6. Equivalence (\leftrightarrow)

De Morgan’s Laws

De Morgan’s Law: A pair of transformation rules to negate statements

Examples:

How-To Apply De Morgan’s:

Hint: If you need to negate a statement with a \to in it, remember that A \rightarrow B \equiv A` \lor B

Tautology and Contradiction

Note: To simplify statements, we use letters near the end of the alphabet, by convention usually P and Q.

Tautology: A well-formed formula that is always true.

Contradiction: A well-formed formula that is always false.

Note: Mathematicians call tautologies and contradictions “intrinsically true” and “intrinsically false”, respectively.

Tautological Equivalence

Logical Equivalence: Two statements are logically equivalent if, and only if, they have identical truth for every possible combination of statement variables.

We can write logical equivalence with \Leftrightarrow and \equiv, like so:

Common Equivalences

CommunicativeA \lor B \equiv B \lor AA \land B \equiv B \land A
Distributive(A \lor B) \lor C \equiv A \lor (B \lor C)(A \land B) \land C \equiv A \land (B \land C)
IdentityA \lor 0 \equiv AA \land 1 \equiv A
ComponentA \lor A' \equiv 1A \land A' \equiv 0

Further Explanation:

Statements in Programs

Conditional statements in programming use logical connectives with statements.

if (outflow > inflow) and not (pressure 1000)
    do something;
else
    do something else

In-Class Exercises

Exercise I: Negation

Problem: Negate the following statements:

  1. If the processor is fast, then the printer is slow (A \to B)
  2. Either the processor is fast or the printer is slow (A \lor B)

Solution:

  1. Change “if then” to “or”, then apply De Morgan’s law \begin{align} (A &\to B)' \\ (A' &\lor B)' \\ A &\land B' \\ \end{align}
  2. Just apply De Morgan’s directly: (A \lor B)' \equiv A' \land B'

Answers:

  1. The processor is fast and the printer is not slow.
  2. The processor is not fast and the printer is not slow

Exercise II: Rewriting into Statement Variables

Problem: Translate the following using statement letters A, T, and E.

Solution:

  1. Let the statement variable be defined as:
  2. “Tax rates will be reduced (T) only if Anita wins the election (A) and the economy remains strong (E)”
  3. T only if ( A and E )”
  4. T \rightarrow (A \land E)

Notes: